from sqlalchemy import Column, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2, FLOAT, NUMBER

# 创建对象的基类
Base = declarative_base()


# 生成结果历史类
class InvoiceInput(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_BI_INVOICE_INPUT'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)
    YEAR = Column(NUMBER)
    GOODS_NAME = Column(VARCHAR2(64))
    COMPANY_NAME = Column(VARCHAR2(128))
    SALER_NAME = Column(VARCHAR2(128))
    FKJE = Column(FLOAT)

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID=int(data.get('ID')) if data.get('ID') is not None else 0,
            YEAR=data.get('YEAR'),
            GOODS_NAME=data.get('GOODS_NAME'),
            COMPANY_NAME=data.get('COMPANY_NAME'),
            SALER_NAME=data.get('SALER_NAME'),
            FKJE=data.get('FKJE')
        )

    def to_dict(self):
        return {
            'ID': self.ID,
            'YEAR': self.YEAR,
            'GOODS_NAME': self.GOODS_NAME,
            'COMPANY_NAME': self.COMPANY_NAME,
            'SALER_NAME': self.SALER_NAME,
            'FKJE': self.FKJE
        }
